package com.skytech.tax.customsdatawarehouse.singlewindow.taxhandle.domain.dao;

import com.skytech.tax.customsdatawarehouse.singlewindow.taxhandle.domain.entity.GuaranteeLetter;
import com.skytech.tax.customsdatawarehouse.singlewindow.taxhandle.domain.entity.GuaranteeMoney;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class GuaranteeLetterDao {

    @Resource
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    private final String insertGuaranteeLetterSql = "INSERT INTO sw_guarantee_letter (seqNo, bankGuaNo, guaNo, data, validDate, socialCreditCode, storageTime)" +
            " VALUES (:seqNo, :bankGuaNo, :guaNo, :data, :validDate, :socialCreditCode, :storageTime)";

    public void save(List<GuaranteeLetter> list) {
        SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch(list);
        namedParameterJdbcTemplate.batchUpdate(insertGuaranteeLetterSql, batch);
    }


    private final String deleteGuaranteeLetterSql = "DELETE FROM sw_guarantee_letter WHERE seqNo IN (:seqNos)";

    public void deleteBy(List<String> seqNos) {
        Map<String, Object> params = new HashMap<>();
        params.put("seqNos", seqNos);
        namedParameterJdbcTemplate.update(this.deleteGuaranteeLetterSql, params);
    }
}
